<?
function ubah(){
	global $inp_par,$inp,$permisi,$sql_tambahan,$cdivisi_kode,$cuserid,$cusername;
        $sqlCek = "select * from tbl_user where user_id='$inp[user_id]' and user_name='$inp[user_name]'";
        $rsCek = dbresult($sqlCek);
        $rCek = pg_fetch_array($rsCek);

        if (trim($inp[pass_lama])==trim($rCek[password])){
            if (trim($inp[pass_baru1])==trim($inp[pass_baru2])){
                $sql = "update tbl_user set password='$inp[pass_baru1]' where user_id='$inp[user_id]' and user_name='$inp[user_name]'";
//                echo $sql;
                dbresult($sql);
                echo "<script>alert('Data Berhasil Di Perbarui..!!')</script>";
                echo "<script>window.location='?inp_par[mode]=edit';</script>";
            }else{
                echo "<script>alert('Password Baru Tidak Sama.. !!')</script>";
                echo "<script>window.history.back();</script>";
            }
        }else{
                echo "<script>alert('Password Lama Salah.. !!')</script>";
                echo "<script>window.history.back();</script>";
        }
}
function form(){
        global $inp_par,$inp,$permisi,$sql_tambahan,$cdivisi_kode,$cuserid,$cusername;
	
	if($inp_par[mode]=="edit"){
		$sql="select * from tbl_user where user_id='$cuserid' and user_name='$cusername'";
		$result = dbresult($sql);//echo $sql;
		$r = pg_fetch_array($result, 0);
        }

        generate_rule("is_isi","inp[user_name]","Anda Harus Mengisi User Name");
	generate_rule("is_isi","inp[pass_lama]","Anda Harus Mengisi Password Lama");
	generate_rule("is_isi","inp[pass_baru1]","Anda Harus Mengisi Password Baru");
        generate_rule("is_countchar","inp[pass_baru1]","Password Baru Min. 6 Char","0","5");
	generate_rule("is_isi","inp[pass_baru2]","Anda Harus Mengisi Password Baru");
	$txtout.=generate_validasi();
        
	$txtout.="<form name=form1 method=\"post\" action=\"?".var_kirim($inp_par)."\" onSubmit=\"return validasi(document.form1);\">
                <table width=700 border=0 align=center cellpadding=3 cellspacing=1 bgcolor=\"C6E6FF\" class=tabel1>
		<tr class=\"tbltagihan\">
		<td colspan=\"3\">FORM GANTI PASSWORD</td>
		</tr>
		<tr bgcolor=\"#FFFFFF\">
		<td width=\"30\"> <div align=center>1.</div></td>
		<td width=170 bgcolor=\"#FFFFFF\">USER NAME</td>
		<td bgcolor=\"#FFFFFF\"><input name='inp[user_name]' class=\"form2\" value='".trim($r[user_name])."' readOnly><input type='hidden' name='inp[user_id]' value='".trim($r[user_id])."'></td>
		</tr>
                <tr bgcolor=\"#FFFFFF\">
		<td> <div align=center>2.</div></td>
		<td bgcolor=\"#FFFFFF\">PASSWORD LAMA</td>
		<td bgcolor=\"#FFFFFF\"><input name='inp[pass_lama]' type=\"password\" class=\"form2\"></td>
		</tr>
		<tr bgcolor=\"#FFFFFF\">
		<td> <div align=center>3.</div></td>
		<td bgcolor=\"#FFFFFF\">PASSWORD BARU (min. 6 char)</td>
		<td><input name=\"inp[pass_baru1]\" type=\"password\" class=\"form2\" id='inputPC' autocomplete='off' onKeyUp='EvalPwdStrength(document.forms[0],this.value);'></td>
		</tr>
                <tr bgcolor=\"#FFFFFF\">
		<td> <div align=center>&nbsp;</div></td>
		<td bgcolor=\"#FFFFFF\">&nbsp;</td>
		<td><table width=\"80%\" cellpadding='0' cellspacing='0' class='pwdChkTbl2'><tbody><tr><td id='idSM1' width='80&amp;percnt;' class='pwdChkCon0' align='center'><span style='font-size:1px'>&nbsp;</span><span id='idSMT1' style='display: none; '>Weak</span></td><td id='idSM2' width='80&amp;percnt;' class='pwdChkCon0' align='center' style='border-left:solid 1px #fff'><span style='font-size:1px'>&nbsp;</span><span id='idSMT0' style='font-weight: normal; color: rgb(102, 102, 102); display: inline; '>Not rated</span><span id='idSMT2' style='display: none; '>Medium</span></td><td id='idSM3' width='80&amp;percnt;' class='pwdChkCon0' align='center' style='border-left:solid 1px #fff'><span style='font-size:1px'>&nbsp;</span><span id='idSMT3' style='display: none; '>Strong</span></td><td id='idSM4' width='80&amp;percnt;' class='pwdChkCon0' align='center' style='border-left:solid 1px #fff'><span style='font-size:1px'>&nbsp;</span><span id='idSMT4' style='display: none; '>BEST</span></td></tr></tbody></table></td>
		</tr>
                <tr bgcolor=\"#FFFFFF\">
		<td> <div align=center>3.</div></td>
		<td bgcolor=\"#FFFFFF\">RETYPE PASSWORD</td>
		<td><div style='float:left'><input class=\"form2\" type=\"password\" name=\"inp[pass_baru2]\" id='retype' size=26 onKeyUp='cekretype();'>&nbsp;&nbsp;&nbsp;</div><div id='cekretype'></div></td>
		</tr>";

	$txtout.="<tr bgcolor=\"#FFFFFF\">
		<td colspan=\"3\"> <div align=\"center\">";
        $txtout.="<span id='tombolsave' ></span>";
	$txtout.="&nbsp;<input type=\"button\" name=\"Submit2222222222\" value=\"Cancel &raquo;\" class=\"tombolgo\" onClick=\"javascript:history.back()\">
		</div></td>
		</tr>
		</table>
		</form>";
	return $txtout;
}

function generate_form($inp_par){
	global $inp_par,$inp;
	switch ($inp_par[mode]){
		case "edit":
			if($inp[aksi]==""){
				$txtout.= form();
			}else{
				$txtout.= ubah();
			}
		break;
	}
	return $txtout;
}

?>
